﻿using System;
using System.Data;
using System.Data.SqlClient;

namespace AbstractSql {
    public class AbsDBTransaction : IAbsDBTransaction {
        #region IDisposable Members

        public void Dispose() {
            throw new NotImplementedException();
        }

        #endregion
        SqlTransaction transaction;
        private AbsDBTransaction() {
            transaction = new SqlConnection().BeginTransaction();
        }
        public static IAbsDBTransaction FromDefault() {
            return new AbsDBTransaction();
        }
        public static IAbsDBTransaction FromNamedConnection(string connectionName) {
            return new AbsDBTransaction();
        }

        static IAbsDBCommandExecution GetCommand(CommandType commandType, string commandText) {
            AbsDBCommandExecution ce = new AbsDBCommandExecution();
            ce.CommandType = commandType;
            ce.CommandText = commandText;
            return ce;
        }

        public IAbsDBCommandExecution StoredProc(string storedProcName) {
            return GetCommand(CommandType.StoredProcedure, storedProcName);
        }
        public IAbsDBCommandExecution SqlCommand(string query) {
            return GetCommand(CommandType.Text, query);
        }

        public void Commit() {
            transaction.Commit();
        }
        public void Rollback() {
            transaction.Rollback();
        }
    }
}